<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>我的信息</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="stylesheet" href="/js/bootstrap-4.1.1-dist/css/bootstrap.min.css">
    <script src="/js/jquery/jquery.min.js"></script>
    <script src="/js/bootstrap-4.1.1-dist/js/bootstrap.min.js"></script>
    <link rel="stylesheet" href="/css/font/css/font-awesome.min.css"/>
    <link rel="stylesheet" href="/css/reset.css"/>
    <link rel="stylesheet" href="/css/message.css" />
    <script src="/js/plugins/jrender/jrender.min.js"></script>
    <link rel="stylesheet" href="/js/plugins/dialog2/dialog.css"/>
    <script src="/js/plugins/dialog2/dialog.min.js"></script>
    <script>
        $(function () {
            //获取当前的登录用户的Id
            var user = JSON.parse(sessionStorage.getItem("user"));
            //查询当前登录用户有聊天记录的人
            $.get("/messages/"+user.id,function (data) {
                var json = {
                    list:data
                }
                $("#receivers").renderValues(json,{
                    getHref : function (item, value) {
                        var url = $(item).data("href");
                        $(item).attr("href",url+value);
                    },
                    getId : function (item, value) {
                        $(item).attr("data-id",value);
                    }
                });
                //获取每个联系人的消息统计
                $.get("/messages/"+user.id+"/oneCount",function (data) {
                    console.log(data);
                    $.each(data,function (index,ele) {
                        $("span[data-id="+ele.id+"]").html(ele.count)
                    })
                })
            });
        });
    </script>
</head>
<body>
    <div class="search-head">
        <div class="row nav-search">
            <div class="col">
                <a href="/mine/message.html">
                    <span><i class="fa fa-chevron-left" ></i></span>
                </a>
            </div>
            <div class="col">
                <span>我的私信</span>
            </div>
            <div class="col"></div>
        </div>
    </div>
    <div id="receivers">
        <div render-loop="list">
        <ul class="list-group">
            <a data-href="/mine/chat2someone.html?receiverId=" render-key="list.id" render-fun="getHref">
                <li class="list-group-item d-flex justify-content-between align-items-center">
                    <div class="item">
                        <img render-src="list.headImgUrl" width="30px"/>
                        <span render-html="list.nickName"></span>
                        <span class="badge badge-danger badge-pill" render-key="list.id" render-fun="getId"></span>
                    </div>
                </li>
            </a>
        </ul>
        </div>
    </div>
</body>
</html>